package com.example.teltest;

import com.fasterxml.jackson.annotation.JsonFormat;

import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.Temporal;
import java.util.ArrayList;
import java.util.List;

public class Calculate {
    public long calculateTimeSpan(LocalDateTime startTime, int inDayLightSavingOfStartTime,LocalDateTime endTime, int inDayLightSavingOfEndTime) {


        java.time.Duration duration = java.time.Duration.between(startTime, endTime);

        long millis = duration.toMillis();
        long minutes;
        if (millis >= 0 && millis / 1000 < 60 || millis % 60000 > 0)
            minutes = millis / 1000 / 60 + 1;
        else
            minutes = millis / 1000 / 60;
        if (inDayLightSavingOfStartTime == 0 && inDayLightSavingOfEndTime == 1)
            minutes = minutes - 60;
        if (inDayLightSavingOfStartTime == 1 && inDayLightSavingOfEndTime == 0)
            minutes = minutes + 60;
        return minutes;
    }



    public BigDecimal calculateFee(long minute) {
        BigDecimal decimal_money = new BigDecimal("0");
        BigDecimal a = new BigDecimal("0.05");
        BigDecimal b = new BigDecimal("1");
        BigDecimal d = new BigDecimal("0.1");
        if (minute > 1800 || minute <= 0) {
            return decimal_money;
        } else {
            if (minute <= 20)
                return decimal_money.multiply(a);
            else
                return decimal_money.add(b.add(BigDecimal.valueOf(minute - 20).multiply(d)));

        }
    }
}
